perf: reduce GC pressure in protobuf serialization#3242
Merged
andygrove merged 2 commits intoJan 22, 2026
Conversation
Replace ByteArrayOutputStream with direct CodedOutputStream serialization to eliminate unnecessary allocations during query plan serialization. This optimization: - Pre-allocates exact buffer size using getSerializedSize() - Eliminates ByteArrayOutputStream's internal buffer resizing - Removes defensive array copying from toByteArray() - Applies to 5 hot paths called per-partition during query execution For a query with 1000 partitions, this eliminates 5000+ unnecessary allocations and array copies, significantly reducing GC pressure. Changes: - operators.scala: getCometIterator() and convertBlock() - CometNativeWriteExec.scala: serializedPlanOpt() and doExecute() - ParquetFilters.scala: createNativeFilters()
hsiang-c
reviewed
Jan 22, 2026
| outputStream.close() | ||
| outputStream.toByteArray | ||
| val size = expr.getSerializedSize | ||
| val bytes = new Array[Byte](size) |
Contributor
There was a problem hiding this comment.
size of Int type, so I think we're safe here.
hsiang-c
reviewed
Jan 22, 2026
| nativeOp.writeTo(out) | ||
| out.close() | ||
| SerializedPlan(Some(out.toByteArray)) | ||
| val size = nativeOp.getSerializedSize |
Contributor
There was a problem hiding this comment.
(minor) We could extract some of the shared code to a utility method but not urgent.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3242 +/- ##
============================================
+ Coverage 56.12% 60.05% +3.92%
- Complexity 976 1429 +453
============================================
Files 119 170 +51
Lines 11743 15782 +4039
Branches 2251 2606 +355
============================================
+ Hits 6591 9478 +2887
- Misses 4012 4983 +971
- Partials 1140 1321 +181 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
mbutrovich
approved these changes
Jan 22, 2026
Contributor
mbutrovich
left a comment
There was a problem hiding this comment.
This looks great, thanks @andygrove!
Member
Author
|
Thanks for the reviews @hsiang-c and @mbutrovich. I will merge this when CI is green. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replace ByteArrayOutputStream with direct CodedOutputStream serialization to eliminate unnecessary allocations during query plan serialization.
This optimization:
For a query with 1000 partitions, this eliminates 5000+ unnecessary allocations and array copies, significantly reducing GC pressure.
Changes:
Which issue does this PR close?
Closes #.
Rationale for this change
What changes are included in this PR?
How are these changes tested?